package purchase.wf;

import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;

import purchase.util.PurchaseConstants;

public class PurchaseDecistionHandler implements DecisionHandler,PurchaseConstants {

	public String decide(ExecutionContext executionContext) throws Exception {
		
		ContextInstance contextInstance = executionContext.getContextInstance();
		
		//get manager's advice
		String managerAdvice = (String)contextInstance.getVariable(this.MANAGER_APPROVE_RESULT); 
		
		//if manager agree purchase
		if (this.MANAGER_APPROVE_RESULT_AGREE.equals(managerAdvice)) {
			return "toend";
			
		//if manager disagree purchase
		} else if (this.MANAGER_APPROVE_RESULT_DISAGREE.equals(managerAdvice)) {
			return "toend";
			
		//if manager back purchase
		} else if (this.MANAGER_APPROVE_RESULT_TOBACK.equals(managerAdvice)) {
			return "tobackmod";
		} 
		
		return "toend";
	}

}
